package com.ycy.ss.sync;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;

import com.ycy.ss.Constant;
import com.ycy.ss.SSUtil;
import com.ycy.ss.status.AllStatus;


public class Info{
	private String fromSite;

	private String type;

	private String content;

	private String attachmentUrl;

	private String infoUrl;

	private byte[] byteInfo;

	private List<String> tags = new LinkedList<String>();

	public String getType(){
		return type;
	}

	public void setType(String type){
		this.type = type;
	}

	public String getContent(){
		return content;
	}

	public void setContent(String content){
		this.content = formatContent(content);
	}

	public String getAttachmentUrl(){
		return attachmentUrl;
	}

	public void setAttachmentUrl(String attachmentUrl){
		this.attachmentUrl = attachmentUrl;
	}

	public byte[] getByteInfo(){
		return byteInfo;
	}

	public void setByteInfo(byte[] byteInfo){
		this.byteInfo = byteInfo;
	}

	public String getInfoUrl(){
		return infoUrl;
	}

	public void setInfoUrl(String infoUrl){
		if (AllStatus.google == null) {
			System.out.println("Info.setInfoUrl: AllStatus.google == null");
		}
		try {
			this.infoUrl = infoUrl != null ? (SSUtil
					.shortLinkbyUrl((Constant.BASE_URL + "redirect.jsp?u=" + URLEncoder.encode(infoUrl, "UTF-8"))))
					: "";
		} catch (Exception e) {
			e.printStackTrace();
			try {
				this.infoUrl = infoUrl != null ? (SSUtil.shortGoogleUrl(AllStatus.google.CREDENTIAL,
						(Constant.BASE_URL + "redirect.jsp?u=" + URLEncoder.encode(infoUrl, "UTF-8")))) : "";
			} catch (UnsupportedEncodingException e1) {
				e1.printStackTrace();
			}

		}

	}

	public List<String> getTags(){
		return tags;
	}

	public void setTags(List<String> tags){
		this.tags = tags;
	}

	public String getFromSite(){
		return fromSite;
	}

	public void setFromSite(String fromSite){
		this.fromSite = fromSite;
	}

	private static String formatContent(String content){
		if (content == null) {
			return "";
		}
		// return content.replace('@', '＠').replaceAll("</?[^>]+>", "");
		return content.replaceAll("</?[^>]+>", "");
	}

}
